#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/4/2 16:35
# @Author  : Chenmm
# @File    : config.py
# @Software: PyCharm

import os
from datetime import timedelta


basedir = os.path.abspath(os.path.dirname(__file__))


class Config:
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'your_secret_key5653745698hftfs'
    SQLALCHEMY_COMMIT_ON_TEARDOWN = False
    FLASKY_MAIL_SUBJECT_PREFIX = '[Flasky]'
    FLASKY_MAIL_SENDER = '119161229@qq.com'
    FLASKY_ADMIN = os.environ.get('FLASKY_ADMIN')
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    
    # Session 设置
    PERMANENT_SESSION_LIFETIME = timedelta(days=30)
    SESSION_COOKIE_NAME = 'my-session'

    # SESSION_TYPE = "filesystem"  # 默认使用文件系统来保存会话
    # SESSION_PERMANENT = True  # 会话是否持久化
    # SESSION_USE_SIGNER = True  # 是否对发送到浏览器上 session 的 cookie 值进行加密
    
    # remember_me选中后，未退出就关闭浏览器可以保存cookie 30天，30天内再次打开浏览器不用登录
    COOKIE_DURATION = timedelta(days=30)
    REMEMBER_COOKIE_DURATION = timedelta(days=30)

    @staticmethod
    def init_app(app):
        pass


class DevelopmentConfig(Config):
    DEBUG = True
    MAIL_SERVER = 'smtp.qq.com'
    MAIL_PORT = 587
    MAIL_USE_TLS = True
    MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
    MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
    SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URI') or \
                                  'mysql+pymysql://root:1993515cmm@127.0.0.1:3306/youlai_flask'

class TestingConfig(Config):
    TESTING = False
    SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URI') or \
                              'sqlite:///' + os.path.join(basedir, 'data-test.sqlite')


class ProductionConfig(Config):
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URI') or \
                              'sqlite:///' + os.path.join(basedir, 'data.sqlite')


config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}
